import React, { useEffect, useState } from 'react'
import { View, Button, Image } from '@tarojs/components'
import Taro, { useDidShow } from '@tarojs/taro'
import RenderView from './components/renderVIew'
import Router from '@/utils/router'
import WechatLogin from './components/wechatLogin'
import './index.scss'
const MicroPage = (props) => {
    const { } = props
    const [userInfo, setUserInfo] = useState({})
    const [visible, setVisible] = useState(false)
    useDidShow(() => {
        setUserInfo(Taro.getStorageSync('userInfo'))
    })
    const handleMethod = (...args) => {
        setUserInfo(args[0])
    }
    useEffect(() => {
        Taro.eventCenter.on('callMethod', handleMethod)
    }, [])
    const { organizationId } = userInfo
    if (!organizationId) {
        return <View className='MicroPage_default_box'>
            <Image src='https://gygj-wechat.oss-cn-hangzhou.aliyuncs.com/wechatImage/indexRender.png' className='MicroPage_default_logo'></Image>
            <Button className='MicroPage_default_btn' onClick={() => {
                Router('selectOrganization')
            }}>立即进入</Button>
            <WechatLogin userInfo={userInfo} visible={visible} onClose={() => setVisible(false)}></WechatLogin>
        </View>
    }
    else {
        return <RenderView userInfo={userInfo}></RenderView>
    }

}
export default MicroPage